package com.js.basicpage.activity;

// Created by JS on 2020/7/30.

import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.MediaController;
import android.widget.VideoView;

import androidx.annotation.Nullable;

import com.js.basicpage.R;
import com.js.basicutils.LogUtils;
import com.js.basicutils.NavigationBarUtil;
import com.js.basicutils.StatusBarUtil;

public class WatchVideoActivity extends BaseLoadingDialogActivity {

    private VideoView videoView;
    private LinearLayout llHeaderBack;

    public static void startActivity(Context context, String videoPath) {
        Intent intent = new Intent(context, WatchVideoActivity.class);
        intent.putExtra("video_path", videoPath);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        int originFlag = getWindow().getDecorView().getSystemUiVisibility();
        getWindow().getDecorView().setSystemUiVisibility(originFlag | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        setContentView(R.layout.activity_watch_video);
        StatusBarUtil.setStatusBarColor(this, R.color.color_actionbar_bg);
        NavigationBarUtil.setSysNavigationTransparent(this);
        initView();
    }

    private void initView() {
        videoView = findViewById(R.id.video_view);
        llHeaderBack = findViewById(R.id.header_back);
        llHeaderBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        String videoPath = getIntent().getStringExtra("video_path");
        LogUtils.d(this, "视频地址：" + videoPath);
        MediaController mediaController = new MediaController(this);
        int currentNavigationBarHeight = NavigationBarUtil.getNavigationBarHeight(this);
        LogUtils.d(this, "高度：" + currentNavigationBarHeight);
        mediaController.setPadding(0, 0, 0, currentNavigationBarHeight);
        videoView.setMediaController(mediaController);
        videoView.setBackgroundResource(R.mipmap.pic_base_splash);
        videoView.setVideoPath(videoPath);
        videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                videoView.setBackground(null);
                videoView.start();
            }
        });
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
//        if (hasFocus) {
//            NavigationBarUtil.setHintBar(this);
//        }
    }
}
